<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.xhd.vo.Fruits"%>
<%@page import="java.util.List"%>
<%@page import="com.xhd.Dao.SalerDaoImpl"%>
<%@page import="com.xhd.Dao.SalerDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link  rel="stylesheet" type="text/css" href="./css/Show_fruit.css"/>
</head>

<body style="background: rgb(254,238,189);">
<div id="page">
	<div id="AppBar">
		<div class="logo">小虎队水果商店
		</div>
		<ul>
			<li><a href="HomePage.jsp">主界面</a></li>
			<li><form action="SalerServlet?method=serchFruit" method="post">
 		<input type="text"  name="serchfruit">	<input type="submit"  name="serch" value="查询">
 		</form></li>
			<li></li>
		</ul>
	</div>
	<!-- 显示水果 -->
	<div id="commodity">
		<%
		List<Fruits> serchlist = new ArrayList<Fruits>();
		serchlist=(List<Fruits>)request.getAttribute("serchlist");
		if(serchlist==null){
		SalerDao sd = new SalerDaoImpl();
		List<Fruits> fruitlist=sd.haveFruitOrNot("待售");
		List<Fruits> fruitlist2=sd.haveFruitOrNot("被冻结");
		Iterator<Fruits> fIter=fruitlist.iterator();
		Iterator<Fruits> fIter2=fruitlist2.iterator();
		if(!fIter.hasNext()&&!fIter2.hasNext()){
    %>
    <div id="inf-box">
			<h6>水果已售空！</h6>
<a href="Jijie.jsp">查看当季水果推荐</a>
		</div>
		<%	
	}else {
		%>
    <div class="low">
        <%

		Fruits fruit=null;
		while(fIter.hasNext()){
			fruit=fIter.next();
        %>
        <ul>
        <%
			int left = 0;
			int right = fruit.getFruit_picture().indexOf("@");
			while(right!=-1) {
			String imagepath = fruit.getFruit_picture().substring(left,right);
		//System.out.println("1:"+imagepath);
		%>
            <li class="img"><img src="./upload/<%=imagepath %>" class="mobile_phone"/></li>
            <%
				left=right+1;
				right=fruit.getFruit_picture().indexOf("@",right+1);
				}
				String imagepath = fruit.getFruit_picture().substring(left,fruit.getFruit_picture().length());
			//System.out.println("2:"+imagepath);
			%>
			<li class="img"><img src="./upload/<%=imagepath %>" class="mobile_phone"/></li>
            <li class="name"><%= fruit.getFruit_name()%></li>
            <li class="money">￥<%= fruit.getFruit_price()%></li>
            <li class="describe"><%=fruit.getFruit_describe()%></li>
            <li class="affirm"><a href="Buy.jsp?order_fruit=<%=fruit.getFruit_name() %>">购买</a></li>
        </ul>
        <%
            }
		Fruits fruit2=null;
		while(fIter2.hasNext()){
			fruit2=fIter2.next();
        %>
        <ul>
        <%
			int left = 0;
			int right = fruit.getFruit_picture().indexOf("@");
			while(right!=-1) {
			String imagepath = fruit2.getFruit_picture().substring(left,right);
			//System.out.println("1:"+imagepath);
			%>
            <li class="img"><img src="./upload/<%=imagepath %>" class="mobile_phone"/></li>
            <%
				left=right+1;
				right=fruit2.getFruit_picture().indexOf("@",right+1);
				}
				String imagepath = fruit2.getFruit_picture().substring(left,fruit2.getFruit_picture().length());
			//System.out.println("2:"+imagepath);
			%>
			<li class="img"><img src="./upload/<%=imagepath %>" class="mobile_phone"/></li>
            <li class="name"><%= fruit2.getFruit_name()%></li>
            <li class="money">￥<%= fruit2.getFruit_price()%></li>
            <li class="describe"><%=fruit2.getFruit_describe()%></li>
            <li class="affirm1">当前水果被冻结，无法购买</li>
        </ul>
        <%
	}
	%>
         </div>
        <%
            }
        %>
        <%
            }
		else{
			Iterator<Fruits> sfIter=serchlist.iterator();
			if (!sfIter.hasNext()){
			%>	
				抱歉，找不到商品！<br>		
				<a href="CheckFruits.jsp">点击此处</a>返回
			<%	
				}
				else {
					Fruits serchfruit=null;
					int count =0;
					while(sfIter.hasNext()){
						serchfruit=sfIter.next();
						//System.out.println("serch:"+serchfruit.getFruit_describe());
						//System.out.println("serch:"+serchfruit.getFruit_state());
						
						if(serchfruit.getFruit_state().equals("待售")||serchfruit.getFruit_state().equals("被冻结")){
						count++;
						
			%>
			 <ul>
        <%
        int left = 0;
		int right = serchfruit.getFruit_picture().indexOf("@");
		while(right!=-1) {
		String imagepath = serchfruit.getFruit_picture().substring(left,right);
		//System.out.println("1:"+imagepath);
		%>
		<li class="img"><img src="./upload/<%=imagepath %>" class="mobile_phone"/></li>
		<%
		left=right+1;
		right=serchfruit.getFruit_picture().indexOf("@",right+1);
		}
		String imagepath = serchfruit.getFruit_picture().substring(left,serchfruit.getFruit_picture().length());
		//System.out.println("2:"+imagepath);
			%>
			<li class="img"><img src="./upload/<%=imagepath %>" class="mobile_phone"/></li>
            <li class="name"><%= serchfruit.getFruit_name()%></li>
            <li class="money">￥<%= serchfruit.getFruit_price()%></li>
            <li class="describe"><%=serchfruit.getFruit_describe()%></li>
            <li class="affirm"><a href="Buy.jsp?order_fruit=<%=serchfruit.getFruit_name() %>">购买</a></li>
        </ul>
        <% 
					}
					
				}
			if(count==0){
			%>
			抱歉，找不到商品！<br>		
			<a href="CheckFruits.jsp">点击此处</a>返回
		<% }
			}
			}
        %>
	</div>
</div>
</body>
</html>